package GUI;

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JPanel;

import java.awt.FlowLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class VerifyDialog extends JDialog {

	public VerifyDialog(final Client_GUI frame,final JPanel torepaint,final boolean menu) {
		
		frame.setEnabled(false);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		setTitle("Are You Sure ?");
		getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JButton btnYes = new JButton("Yes");
		btnYes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				frame.safeToClear = true;
				frame.setEnabled(true);
				
				if (menu == false){ //only repaint main
					frame.RepaintMain(torepaint);
				}else{ //logoff has been requested
					
					frame.RepaintMenu(0);
					
					frame.Login(frame.client.GetUID(), "", false); //password is irrelivent for logoff
					
					
					frame.setTopFrameTitle("Hello System User!");
					frame.labelMeesege.setVisible(false);
					frame.resultLabel.setVisible(false);

					frame.btnLogoff.setVisible(false);
					frame.RepaintMenu(0);
					
					try{
						frame.client.closeConnection();
					}catch(IOException err){}
				}
				
				setVisible(false);
			}
		});
		getContentPane().add(btnYes);
		
		JButton btnNo = new JButton("No");
		btnNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				frame.setEnabled(true);
			}
		});
		getContentPane().add(btnNo);
		
		this.setSize(200, 70);
		this.setLocation(400, 200);
		this.setVisible(true);
		this.setResizable(false);
		
	}

	public VerifyDialog(Frame owner) {
		super(owner);
	}

	public VerifyDialog(Dialog owner) {
		super(owner);
	}

	public VerifyDialog(Window owner) {
		super(owner);
	}

	public VerifyDialog(Frame owner, boolean modal) {
		super(owner, modal);
	}

	public VerifyDialog(Frame owner, String title) {
		super(owner, title);
	}

	public VerifyDialog(Dialog owner, boolean modal) {
		super(owner, modal);
	}

	public VerifyDialog(Dialog owner, String title) {
		super(owner, title);
	}

	public VerifyDialog(Window owner, ModalityType modalityType) {
		super(owner, modalityType);
	}

	public VerifyDialog(Window owner, String title) {
		super(owner, title);
	}

	public VerifyDialog(Frame owner, String title, boolean modal) {
		super(owner, title, modal);
	}

	public VerifyDialog(Dialog owner, String title, boolean modal) {
		super(owner, title, modal);
	}

	public VerifyDialog(Window owner, String title, ModalityType modalityType) {
		super(owner, title, modalityType);
	}

	public VerifyDialog(Frame owner, String title, boolean modal,
			GraphicsConfiguration gc) {
		super(owner, title, modal, gc);
	}

	public VerifyDialog(Dialog owner, String title, boolean modal,
			GraphicsConfiguration gc) {
		super(owner, title, modal, gc);
	}

	public VerifyDialog(Window owner, String title, ModalityType modalityType,
			GraphicsConfiguration gc) {
		super(owner, title, modalityType, gc);
	}

}
